/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package toolz;

/**
 *
 * @author bunkowski
 */
import java.awt.Color;
import java.awt.Component;
import java.util.Date;

import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class ColorColumnRenderer extends JLabel implements TableCellRenderer{
	
	public static final long serialVersionUID = 1L;
	
    private Color colorSelected = new Color(0, 0, 255);
    private Color colorFocus = new Color(0, 0, 200);
    private Color colorNormal;
 
    public ColorColumnRenderer(Color color){
        setOpaque( true );
        colorNormal = color;
    }
    
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        
        // die normalen Farben
        setForeground( Color.BLACK );
        if( hasFocus )
            setBackground( colorFocus );
        else if( isSelected )
            setBackground( colorSelected );
        else
            setBackground( colorNormal );
        
        setText( null );
        setIcon( null );
        
        if( value instanceof Date )
            setText( ((Date)value).toGMTString() );
        else if( value instanceof Icon )
            setIcon( (Icon)value );
        else if( value instanceof Color ){
            Color color = (Color)value;
            setForeground( color );
            setText( color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() );
        }
        else if( value instanceof Boolean ){
            if( ((Boolean)value).booleanValue() )
                setText( "yes" );
            else
                setText( "no" );
        }
        else
            setText( value.toString() );
        
        return this;
    }
}